  <template>
  <div class="JNPF-common-layout">
    <div class="JNPF-common-layout-center">
      <el-row class="JNPF-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="6">
            <el-form-item label="组织单位">
              <el-select v-model="query.zzdw" placeholder="组织单位" clearable>
                <el-option
                  v-for="(item, index) in zzdwOptions"
                  :key="index"
                  :label="item.F_FullName"
                  :value="item.F_Id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="排查类型">
              <el-select v-model="query.pclx" placeholder="排查类型" clearable>
                <el-option
                  v-for="(item, index) in pclxOptions"
                  :key="index"
                  :label="item.LX"
                  :value="item.ID"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()"
                >查询</el-button
              >
              <el-button icon="el-icon-refresh-right" @click="reset()"
                >重置</el-button
              >
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="JNPF-common-layout-main JNPF-flex-main">
        <div class="JNPF-common-head">
          <div>
            <el-button
              type="primary"
              icon="el-icon-plus"
              @click="addOrUpdateHandle()"
            >
              新增
            </el-button>
            <el-button
              type="text"
              icon="el-icon-download"
              @click="exportData()"
            >
              导出
            </el-button>
          </div>
          <div class="JNPF-common-head-right">
            <el-tooltip effect="dark" content="刷新" placement="top">
              <el-link
                icon="icon-ym icon-ym-Refresh JNPF-common-head-icon"
                :underline="false"
                @click="reset()"
              />
            </el-tooltip>
            <screenfull :isContainer="true" />
            <el-tooltip effect="dark" content="列设置" placement="top">
              <el-link
                icon="icon-ym icon-ym-options JNPF-common-head-icon"
                :underline="false"
              />
            </el-tooltip>
          </div>
        </div>
        <JNPF-table v-loading="listLoading" :data="list">
          <el-table-column prop="jhmc" label="计划名称" align="left" />
          <el-table-column label="组织单位" prop="zzdw" algin="left">
            <template slot-scope="scope">{{
              scope.row.zzdw | dynamicText(zzdwOptions)
            }}</template>
          </el-table-column>
          <el-table-column label="风险点" prop="fxdMc" algin="left">
            <template slot-scope="scope">{{
              scope.row.fxdMc | dynamicText(fxdOptions)
            }}</template>
          </el-table-column>
          <!-- <el-table-column label="风险点类型"  prop="fxdlx" algin="left">
						<template slot-scope="scope">{{ scope.row.fxdlx | dynamicText(fxdlxOptions) }}</template>
					</el-table-column> -->
          <el-table-column label="排查人" prop="pcrMc" algin="left">
            <template slot-scope="scope">{{
              scope.row.pcrMc | dynamicText(pcrOptions)
            }}</template>
          </el-table-column>
          <el-table-column label="被查单位" prop="bcdw" algin="left">
            <template slot-scope="scope">{{
              scope.row.bcdw | dynamicText(bcdwOptions)
            }}</template>
          </el-table-column>
          <el-table-column prop="pcksrq" label="排查开始日期" align="left" />
          <el-table-column prop="pcjsrq" label="排查结束日期" align="left" />
          <el-table-column prop="cjsj" label="创建时间" align="left" />
          <el-table-column label="状态" prop="zt" algin="left">
            <template slot-scope="scope">{{
              scope.row.zt | dynamicText(ztOptions)
            }}</template>
          </el-table-column>
          <el-table-column label="排查类型" prop="pclx" algin="left">
            <template slot-scope="scope">{{
              scope.row.pclx | dynamicText(pclxOptions)
            }}</template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" width="200">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="scope.row.zt == 1"
                @click="addOrUpdateHandle(scope.row.id)"
              >
                编辑
              </el-button>
              <el-button
                type="text"
                v-if="scope.row.zt == 1"
                @click="handleDel(scope.row.id)"
                class="JNPF-table-delBtn"
              >
                删除
              </el-button>
              <el-button
                type="text"
                @click="addOrUpdateHandle(scope.row.id, true)"
              >
                详情
              </el-button>
              <el-button
                type="text"
                v-if="scope.row.zt == 1"
                @click="addPf(scope.row.id)"
              >
                派发
              </el-button>
            </template>
          </el-table-column>
        </JNPF-table>
        <pagination
          :total="total"
          :page.sync="listQuery.currentPage"
          :limit.sync="listQuery.pageSize"
          @pagination="initData"
        />
      </div>
    </div>
    <JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh" />
    <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
  </div>
</template> 
<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import JNPFForm from "./Form";
import ExportBox from "./ExportBox";
import { previewDataInterface } from "@/api/systemData/dataInterface";

export default {
  components: { JNPFForm, ExportBox },
  data() {
    return {
      showAll: false,
      query: {
        zzdw: undefined,
        pclx: undefined,
      },
      defaultProps: {
        children: "children",
        label: "fullName",
      },
      list: [],
      listLoading: true,
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,

        sort: "desc",
        sidx: "",
      },
      formVisible: false,
      exportBoxVisible: false,
      columnList: [
        { prop: "jhmc", label: "计划名称" },
        { prop: "zzdw", label: "组织单位" },
        { prop: "fxd", label: "风险点" },
        { prop: "fxdlx", label: "风险点类型" },
        { prop: "pcr", label: "排查人" },
        { prop: "bcdw", label: "被查单位" },
        { prop: "pcksrq", label: "排查开始日期" },
        { prop: "pcjsrq", label: "排查结束日期" },
        { prop: "cjsj", label: "创建时间" },
        { prop: "zt", label: "状态" },
        { prop: "pclx", label: "排查类型" },
      ],
      zzdwOptions: [],
      fxdOptions: [],
      fxdlxOptions: [],
      pcrOptions: [],
      bcdwOptions: [],
      ztOptions: [
        { fullName: "未派发", id: "1" },
        { fullName: "进行中", id: "2" },
        { fullName: "已结束", id: "3" },
      ],
      pclxOptions: [],
    };
  },
  computed: {},
  created() {
    this.initData();

    this.getzzdwOptions();
    this.getbcdwOptions();
    this.getpclxOptions();
  },
  methods: {
    getzzdwOptions() {
      previewDataInterface("772d2cbcadd24df79243e3d92ef5f690").then((res) => {
        this.zzdwOptions = res.data;
      });
    },
    getbcdwOptions() {
      previewDataInterface("772d2cbcadd24df79243e3d92ef5f690").then((res) => {
        this.bcdwOptions = res.data;
      });
    },
    getpclxOptions() {
      previewDataInterface("7ffbe4af1ea946dabb20e1dc367220a9").then((res) => {
        this.pclxOptions = res.data;
      });
    },
    initData() {
      this.listLoading = true;
      let query = {
        ...this.listQuery,
        ...this.query,
      };
      request({
        url: `/api/System/pcjh`,
        method: "get",
        data: query,
      }).then((res) => {
        let listData = res.data.list;
        if (listData.length > 0) {
          previewDataInterface("8bca424f16d6448ab09e57a028853aa9").then((d) => {
            for (let i = 0; i < listData.length; i++) {
              let fxdArr = [];
              let szString = listData[i].sz;
              let szArr1 = szString.replace(/\|/g, ",");
              let szArr = JSON.parse(szArr1);
              if (szArr.length > 0) {
                for (let r = 0; r < szArr.length; r++) {
                  fxdArr.push(szArr[r].mc);
                }
              }
              listData[i].fxdMc = fxdArr.join(",");
              //   排查人
              if (listData[i].pcr.length > 0) {
                let pcrMcArr = [];
                listData[i].pcr.forEach((n) => {
                  d.data.forEach((t) => {
                    if (t.F_Id == n) {
                      pcrMcArr.push(t.F_RealName);
                    }
                  });
                });
                listData[i].pcrMc = pcrMcArr.join(",");
              }
            }
            this.list = listData;
            this.total = res.data.pagination.total;
            this.$nextTick(() => {
              this.tableHeight = "100%";
            });
          });
        }
        this.listLoading = false;
      });
    },
    handleDel(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        type: "warning",
      })
        .then(() => {
          request({
            url: `/api/System/pcjh/${id}`,
            method: "DELETE",
          }).then((res) => {
            this.$message({
              type: "success",
              message: res.msg,
              onClose: () => {
                this.initData();
              },
            });
          });
        })
        .catch(() => {});
    },
    addOrUpdateHandle(id, isDetail) {
      this.formVisible = true;
      this.$nextTick(() => {
        this.$refs.JNPFForm.init(id, isDetail);
      });
    },
    exportData() {
      this.exportBoxVisible = true;
      this.$nextTick(() => {
        this.$refs.ExportBox.init(this.columnList);
      });
    },
    download(data) {
      let query = { ...data, ...this.listQuery, ...this.query };
      request({
        url: `/api/System/pcjh/Actions/Export`,
        method: "POST",
        data: query,
      }).then((res) => {
        if (!res.data.url) return;
        window.location.href = this.define.comUrl + res.data.url;
        this.$refs.ExportBox.visible = false;
        this.exportBoxVisible = false;
      });
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,

        sort: "desc",
        sidx: "",
      };
      this.initData();
    },
    refresh(isrRefresh) {
      this.formVisible = false;
      if (isrRefresh) this.reset();
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,

        sort: "desc",
        sidx: "",
      };
      this.initData();
    },
    addPf(Id) {
      request({
        url: `/api/System/pcjh/Actions/PF/` + Id,
        method: "GET",
      }).then((res) => {
        this.$message({
          message: res.msg,
          type: "success",
          duration: 1000,
          onClose: () => {
            this.initData();
          },
        });
      });
    },
  },
};
</script>